const config = require('../../../utils/config.js')
const util = require('../../../utils/util.js')
const api = require('../../../utils/api.js');
const regeneratorRuntime = require('../../../utils/runtime.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    showLogin: false,
    isAuthor: false,
    showRedDot: '',
    signedDays: 0,//连续签到天数
    signed: 0,
    isShow: false,
    signBtnTxt: "每日签到",
    iconList: [{
      icon: 'favorfill',
      color: 'grey',
      badge: 0,
      name: '参与队伍',
      count: 3,
      bindtap: "bindCollect"
    }/*, {
      icon: 'appreciatefill',
      color: 'green',
      badge: 0,
      name: '关注用户',
      bindtap: "bindZan"
    }*/, {
      icon: 'noticefill',
      color: 'yellow',
      badge: 0,
      count: 3,
      name: '关注竞赛',
      bindtap: "bindNotice"
    }, {
      icon: 'goodsfavor',
      color: 'orange',
      badge: 0,
      count: 3,
      name: '关注活动',
      bindtap: "bindPoint"
    }],
  },

  onShow: async function () {
    // await this.getMemberInfo()
    // app.getInfo();

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    let that = this;
    let showRedDot = wx.getStorageSync('showRedDot');
    setTimeout(() => {
      let userinfo = app.globalData.user;
      if (userinfo) {
        this.setPageData(userinfo)
      } else {
        api.launch().then((back) => {
          if (back.errcode == 0) {
            userinfo = back.data.user;
            this.setPageData(userinfo)
          }
        })
      }
    }, 700)

    /*that.setData({
      showRedDot: showRedDot
    });*/
    //await that.checkAuthor()
    //await that.getMemberInfo()
  },

  onShareAppMessage: function () {
    let share = this.data.shareData;
    let path = 'pages/detail/detail?id='+share.id;
    let shareSet = {
      title: "邀请你参加"+share.title,
      path: '/pages/index/index?type=pageJump&path=' + encodeURIComponent(path),
      imageUrl: share.imageUrl,
      success: function (res) {
　　　　　　// 转发成功之后的回调
　　　　　　if (res.errMsg == 'shareAppMessage:ok') {
　　　　　　}
　　　　},
    }
    return shareSet;
  },
  setPageData: function (userinfo) {
    this.setData({
      userInfo: userinfo,
      "iconList[0].count": userinfo.join_team_count,
      "iconList[1].count": userinfo.follow_competition_count,
      "iconList[2].count": userinfo.follow_activity_count,
    })
  },
  /**
   * 返回
   */
  navigateBack: function (e) {
    wx.switchTab({
      url: '../index/index'
    })
  },

  /**
   * 获取用户头像
   * @param {} e 
   */
  getUserInfo: function (e) {
    console.log(e.detail.userInfo)
    if (e.detail.userInfo) {
      app.globalData.userInfo = e.detail.userInfo
      this.setData({
        showLogin: !this.data.showLogin,
        userInfo: e.detail.userInfo
      });
    } else {
      wx.switchTab({
        url: '../index/index'
      })
    }
  },


  /**
   * 跳转我的收藏
   * @param {*} e 
   */
  bindCollect: async function (e) {
    wx.navigateTo({
      url: '../mine/collection/collection?type=1'
    })
  },







  hideModal(e) {
    this.setData({
      isShow: false
    })
  },
})

